<?php
    class App extends CActiveRecord
    {
        public static function model($className = __CLASS__) {
            return parent::model ( $className );
        }

        public function tableName() {                  
            return 'c_app';
        }
        /* Lấy app clip */
        public function getAppClip()
        {
            $sql = "SELECT id, title,introtext, alias,picture,percent_wapmaster,download,create_date FROM c_app WHERE  id = 3";
            $command = Yii::app()->db->createCommand($sql);
            $rows = $command->queryRow();
            return $rows;
        }
        /* Lấy app khác */
        public function getOtherApp($currentPage, $numberRecordPerPage)
        {
            $startRecord = ($currentPage - 1) * $numberRecordPerPage;  
            $sql = "SELECT id, title,introtext, alias,picture,download,percent_wapmaster,create_date,isJava,isAndroid,isIos,isRim FROM c_app WHERE  id != 3 AND status =1 ORDER BY position ASC LIMIT " . $startRecord . ", " . $numberRecordPerPage;
            $command = Yii::app()->db->createCommand($sql);
            $rows = $command->queryAll();   
            return $rows;
        }
        public function getOtherAppHot($currentPage, $numberRecordPerPage)
        {
            $startRecord = ($currentPage - 1) * $numberRecordPerPage;  
            $sql = "SELECT id, title,introtext, alias,picture,percent_wapmaster,download,create_date,isJava,isAndroid,isIos,isRim FROM c_app WHERE  id != 3 AND status =1 ORDER BY download DESC  LIMIT " . $startRecord . ", " . $numberRecordPerPage;
            $command = Yii::app()->db->createCommand($sql);
            $rows = $command->queryAll();   
            return $rows;
        }
        
        public function getTotalApp()
        {
            $sql = "SELECT count(id) FROM c_app WHERE  id != 3 AND status =1 ";
            $command = Yii::app()->db->createCommand($sql);
            $rows = $command->queryRow();        
            return $rows["count(id)"];
        }
         /* Thông tin về ứng dụng */
        public function getInfoApp($id)
        {
            $sql = "SELECT * FROM c_app WHERE id=" . $id;
            $command = Yii::app()->db->createCommand($sql);
            $rows = $command->queryRow();  
            return $rows;   
        }
        
          public function getListAppEmbed()
        {
            $sql = "SELECT * FROM c_app WHERE status = 1  ORDER BY position";
            $command = Yii::app()->db->createCommand($sql);
            $rows = $command->queryAll();     
            return $rows;   
        }
        
    } 
?>
